import * as api from "../../api/address";

Component({
    options:{
        styleIsolation:'isolated'
    },
    properties:{
        pickerId:{
            type:Array,
            value:[],
            observer: function (val) {
                if( val.length >0 ){
                    if(val[0]){
                        api.findChildAddress({
                            parentId:val[0]
                        })
                        .then((res)=>{
                            if(res && res.length > 0){
                                let index = res.findIndex((el)=>{
                                    return el.id == val[1];
                                });
                                this.setData({
                                    list:res,
                                    index
                                })
                            }
                        })
                    }
                }
            }
        },
        disabled:{
            type:Boolean,
            value:true,
        }
    },
    data:{
        list:[],
        index:0,
        areaCode:""
    },
    methods: {
        bindPickerChange(e){
            
            let index = e.detail.value*1;
            let list = this.data.list;

            if(index !== this.data.index*1 ){
                this.setData({
                    index:index
                });
                
                this.triggerEvent("change", {
                    id: list[index].id,
                    name: list[index].regionName
                })
            }
            
        }
    },
})
